/*
 * SimulationNode.h
 *
 *  Created on: 30/10/2011
 *      Author: godinho
 */

#ifndef SIMULATIONNODE_H_
#define SIMULATIONNODE_H_

#include <string>
#include <vector>
#include <map>

class NodeInput;
class TLSPhase;

class SimulationNode {
public:

	SimulationNode(std::string id, int x, int y);

	virtual ~SimulationNode();

	NodeInput* getNodeInput(SimulationNode* node);

	std::map<SimulationNode*, NodeInput*> getNodeInputMap();

	std::string getId();

	TLSPhase* getCurrentPhase();

	std::vector<TLSPhase*> getPhases();

	void addIncomingNode(SimulationNode* incoming, int travelTime);

	void addOutcomingNode(SimulationNode* outcoming);

	void addPhase(TLSPhase* phase);

	int getX();

	int getY();

	std::vector<SimulationNode*> getOutcomingNodes();

	/**
	 * @return true if it is time to a phase switch
	 */
	bool decrementCurrentPhaseTime();

	void nextPhase();

	void collectCars();

	/**
	 * Returns true when the node is on network border. It means that there
	 * is only incoming nodes to it.
	 *
	 * @return true if this node is on network border.
	 */
	bool isBorder();

	bool isNetworkOutputNode();

	bool isNetworkInputNode();

	bool hasPhases();

private:
	std::string mId;

	TLSPhase* mCurrentPhase;

	std::vector<TLSPhase*> mPhases;

	std::map<SimulationNode*, NodeInput*> mNodeInput;

	std::vector<SimulationNode*> mOutcomingNode;

	int mX;

	int mY;

	int mCurrentPhaseTimeout;

	int mCurrentPhaseIndex;
};

#endif /* SIMULATIONNODE_H_ */
